package handler

import (
	"com.yy.api/my_gateway/internal/proxy"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ChatProxyHandler(proxies map[string]proxy.HttpProxy) gin.HandlerFunc {
	return func(c *gin.Context) {
		providerName := c.GetHeader("X-Provider")
		if providerName == "" {
			providerName = "openai"
		}
		p, exists := proxies[providerName]
		if !exists {
			c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "provider not found"})
			return
		}
		p.ServeHTTP(c.Writer, c.Request)
	}
}
